/**
 * @param {String} url
 * @param {String} method
*/
function requestData(url, method) {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest()

    xhr.open(method, url)
    xhr.send(null)
    xhr.onreadystatechange = function() {
      const { readyState, status, response } = this
      if (readyState !== 4) return
      (status >= 200) && (status < 400) ? resolve(response) : reject('error')
    }
  })
}
